/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoCodeTest.go			*/
/********************************************************/

package main

import (
	. "GoGlb"
	C "GoCls"
)

func main() {
	/* JSON */
	type adver struct {
		Name	string "name"
		Area	string "area"
		City	string "city"
		Type	string "type"
		Size	string "size"
		Path	string "path"
	}
	adv := &adver{"AdvName", "AdvArea", "AdvCity", "AdvType", "AdvSize", "AdvPath"}

	ejs, _ := C.GoJsonEncode(adv)
	GoPrtln("JSON:", string(ejs))

	/* BASE32 */
	src := "Package baseXX implements baseXX encoding as specified by RFC 4648."

	base32 := new(C.GoBase32)
	base32.GoBase32New(C.GO_CD_TB32)
	dst32 := base32.GoBase32Encode([]byte(src))
	GoPrtln("ASII32_1:", string(src))
	GoPrtln("BASE32_1:", string(dst32))

	tmp32, num32 := base32.GoBase32Decode(dst32)
	if num32 > 0 {
		GoPrtln("BASE32_2:", string(dst32))
		GoPrtln("ASII32_2:", string(tmp32))
	} else {
		GoPrtln("GoBase32Decode error")
	}

	/* BASE64 */
	base64 := new(C.GoBase64)
	base64.GoBase64New(C.GO_CD_TB64)
	dst64 := base64.GoBase64Encode([]byte(src))
	GoPrtln("ASII64_1:", string(src))
	GoPrtln("BASE64_1:", string(dst64))

	tmp64, num64 := base64.GoBase64Decode(dst64)
	if num64 > 0 {
		GoPrtln("BASE64_2:", string(dst64))
		GoPrtln("ASII64_2:", string(tmp64))
	} else {
		GoPrtln("GoBase64Decode error")
	}

	/* URLCODE */
	srcu := "updateversion={\"bdapplocatesetting\":0,\"format\":\"json\"}"
	srcd := "updateversion=%7B%22bdapplocatesetting%22%3A0%2C%22format%22%3A%22json%22%7D"

	ecode := C.GoUrlEncode([]byte(srcu))
	GoPrtln("SrcUrl:", string(srcu))
	GoPrtln("Encode:", string(ecode))

	dcode := C.GoUrlDecode([]byte(srcd))
	GoPrtln("DstUrl:", string(srcd))
	GoPrtln("Decode:", string(dcode))

	// ENCRYPT
	srce := "Copyright (C) 2016 Gong Li Bin		 (GoLib-1.0.0)"

	esrc := C.GoInfoEncrypt(C.GO_CD_ENCD, []byte(C.GO_CD_KEYS), []byte(srce))
	GoPrtln("SrcEnc:", string(srce))
	GoPrtln("Encryt:", string(esrc))

	edst := C.GoInfoEncrypt(C.GO_CD_DECD, []byte(""), []byte(esrc))
	GoPrtln("Encryt:", string(esrc))
	GoPrtln("Decryt:", string(edst))
}
